package cn.wsn2018.tools.model;

import cn.wsn2018.tools.util.StringUtil;

/**
 * @program: tools
 * @description
 * @author: songDaisong
 * @create: 2020-01-15 14:57
 **/
public class SystemConfig {

    //单例双重锁检查加锁
    private volatile static SystemConfig systemConfig;

    public static SystemConfig getInstance(){
        if(systemConfig==null){
            synchronized (SystemConfig.class){
                if(systemConfig==null){
                    systemConfig=new SystemConfig();
                }
            }

        }
        return systemConfig;
    }

    private SystemConfig() {
    }

    public void setSystemConfig(SystemConfig obj){

        synchronized (SystemConfig.class){
            if(obj!=null){
                if(!StringUtil.isEmptyString(obj.getId())){
                    systemConfig.setId(obj.getId());
                }
                if(!StringUtil.isEmptyString(obj.getPwdValidTime())){
                    systemConfig.setPwdValidTime(obj.getPwdValidTime());
                }
                if(!StringUtil.isEmptyString(obj.getLogMaxVolume())){
                    systemConfig.setLogMaxVolume(obj.getLogMaxVolume());
                }
                if(!StringUtil.isEmptyString(obj.getConcurrentMaxNum())){
                    systemConfig.setConcurrentMaxNum(obj.getConcurrentMaxNum());
                }
                if(!StringUtil.isEmptyString(obj.getLockedTime())){
                    systemConfig.setLockedTime(obj.getLockedTime());
                }
                if(!StringUtil.isEmptyString(obj.getAccountValidTime())){
                    systemConfig.setAccountValidTime(obj.getAccountValidTime());
                }
                if(!StringUtil.isEmptyString(obj.getSessionMaxOverTime())){
                    systemConfig.setSessionMaxOverTime(obj.getSessionMaxOverTime());
                }
                if(!StringUtil.isEmptyString(obj.getLoginFailedNum())){
                    systemConfig.setLoginFailedNum(obj.getLoginFailedNum());
                }
//                if(!StringUtil.isEmptyString(obj.getNotLoginTime())){
//                    systemConfig.setNotLoginTime(obj.getNotLoginTime());
//                }
            }
        }
    }


    //默认值

    //对未登录账号进行休眠    默认90天
    public static final String NOT_LOGIN_TIME="90";
    //密码口令的有效期 默认90天
    public static final String PASSWORD_VALID_TIME="90";
    //临时账号有效期,到时间后转为休眠   默认90天(1-90天)
    public static final String ACCOUNT_VALID_TIME="90";
    //登录失败次数    默认5次(1-10)
    public static final String LOGIN_FAILED_Num="10";
    //登录失败后锁定时长,至少锁定20分钟和由管理员锁定   默认值20分钟
    public static final String LOCKED_Time="20";
    //会话超时时间
    public static final String SESSION_MAX_OVERTime="30";
    //最大并发数(允许同时在线人数) 默认：50 (>=0)
    public static final String CONCURRENT_MAX_Num="50";
    //审计日志存储空间上限,至少1GB  默认:1GB
    public static final String LOG_MAX_VOLUME="1";



    /**
     * 主键
     * */
    private String id;
    /**
     * 未登录时长
     */
    //private String notLoginTime=NOT_LOGIN_TIME;

    /**
     * 密码有效期：修改密码后，有效时长
     * */
    private String pwdValidTime=PASSWORD_VALID_TIME;
    /**
     * 临时账号有效期：
     * */
    private String accountValidTime=ACCOUNT_VALID_TIME;
    /**
     * 登录失败达到一定数量后锁定一定的时间，不让其登录
     * */
    private String lockedTime=LOCKED_Time;
    /**
     * 登录失败的次数
     * */
    private String loginFailedNum=LOGIN_FAILED_Num;
    /**
     * 会话超时时间
     * */
    private String sessionMaxOverTime=SESSION_MAX_OVERTime;
    /**
     *最大并发数
     * */
    private String concurrentMaxNum=CONCURRENT_MAX_Num;
    /**
     * 日志容量上限
     * */
    private String logMaxVolume=LOG_MAX_VOLUME;


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPwdValidTime() {
        return pwdValidTime;
    }

    public void setPwdValidTime(String pwdValidTime) {
        this.pwdValidTime = pwdValidTime;
    }

//    public String getNotLoginTime() {
//        return notLoginTime;
//    }
//
//    public void setNotLoginTime(String notLoginTime) {
//        this.notLoginTime = notLoginTime;
//    }

    public String getAccountValidTime() {
        return accountValidTime;
    }

    public void setAccountValidTime(String accountValidTime) {
        this.accountValidTime = accountValidTime;
    }

    public String getLockedTime() {
        return lockedTime;
    }

    public void setLockedTime(String lockedTime) {
        this.lockedTime = lockedTime;
    }

    public String getLoginFailedNum() {
        return loginFailedNum;
    }

    public void setLoginFailedNum(String loginFailedNum) {
        this.loginFailedNum = loginFailedNum;
    }

    public String getSessionMaxOverTime() {
        return sessionMaxOverTime;
    }

    public void setSessionMaxOverTime(String sessionMaxOverTime) {
        this.sessionMaxOverTime = sessionMaxOverTime;
    }

    public String getConcurrentMaxNum() {
        return concurrentMaxNum;
    }

    public void setConcurrentMaxNum(String concurrentMaxNum) {
        this.concurrentMaxNum = concurrentMaxNum;
    }

    public String getLogMaxVolume() {
        return logMaxVolume;
    }

    public void setLogMaxVolume(String logMaxVolume) {
        this.logMaxVolume = logMaxVolume;
    }

    @Override
    public String toString() {
        return "SystemConfig{" +
                ", pwdValidTime=" + pwdValidTime +
                ", accountValidTime=" + accountValidTime +
                ", lockedTime=" + lockedTime +
                ", loginFailedNum=" + loginFailedNum +
                ", sessionMaxOverTime=" + sessionMaxOverTime +
                ", concurrentMaxNum=" + concurrentMaxNum +
                ", logMaxVolume=" + logMaxVolume +
                '}';
    }
}
